//
//  TabBarViewController.m
//  tabBarViewController
//
//  Created by Bc_Ltf on 15/3/25.
//  Copyright (c) 2015年 Bc_ltf. All rights reserved.
//

#import "TabBarViewController.h"

#import "HMTabBar.h"




@interface TabBarViewController ()<UITabBarControllerDelegate>


//@interface TabBarViewController ()<HMTabBarDelegate,UITabBarControllerDelegate>




@property (nonatomic, weak) UIViewController *lastSelectedViewContoller;
@end

@implementation TabBarViewController
{
    NSString *str;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.delegate = self;
    self.tabBar.tintColor =kMainColor;
//    self.tabBar.barTintColor = kMainColor;
   
   
    
    // 添加所有的子控制器
    [self addAllChildVcs];

    
  
}




/**
 *  创建自定义tabbar
 */
- (void)addCustomTabBar
{
    // 创建自定义tabbar
    HMTabBar *customTabBar = [[HMTabBar alloc] init];
    customTabBar.tabBarDelegate = self;
    // 更换系统自带的tabbar
    [self setValue:customTabBar forKeyPath:@"tabBar"];
}

/**
 *  添加所有的子控制器
 */
- (void)addAllChildVcs
{
    
    
    
    UIViewController *vc1 = [[ViewController1 alloc] init];
    [self addOneChlildVc:vc1 title:@"免费" imageName:@"免费" selectedImageName:@"免费绿"];
    
    

    //需求变化,中间突出来的按钮 是平级的VC
    UIViewController *vc2 = [[ViewController2 alloc] init];
    [self addOneChlildVc:vc2 title:@"商城" imageName:@"商城" selectedImageName:@"商城绿"];
    
    
   

    
    UIViewController *vc3 = [[ViewController3 alloc] init];
    [self addOneChlildVc:vc3 title:@"购物车" imageName:@"购物车" selectedImageName:@"购物车绿"];

 
    UIViewController *vc4 = [[ViewController4 alloc] init];
    [self addOneChlildVc:vc4 title:@"我的" imageName:@"我的" selectedImageName:@"我的绿"];

    
    
//    UIViewController *vc5 = [[UIViewController alloc] init];
//    [self addOneChlildVc:vc5 title:@"vc5" imageName:@"" selectedImageName:@""];
//    
    //self.selectedIndex = 1;
    
    
}

/**
 *  添加一个子控制器
 *
 *  @param childVc           子控制器对象
 *  @param title             标题
 *  @param imageName         图标
 *  @param selectedImageName 选中的图标
 */
- (void)addOneChlildVc:(UIViewController *)childVc title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName
{
    //    // 设置标题
    childVc.title = title;
    
    // 设置图标
    
    childVc.tabBarItem.image =  [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    

    
    // 添加为tabbar控制器的子控制器
    JSNavigationController *nav = [[JSNavigationController alloc] initWithRootViewController:childVc];
    [self addChildViewController:nav];
}

#pragma mark - HMTabBarDelegate
- (void)tabBarDidClickedPlusButton:(HMTabBar *)tabBar
{
    // 弹出发微博控制器
    //
    //        HMComposeViewController *compose = [[HMComposeViewController alloc] init];
    //        HMNavigationController *nav = [[HMNavigationController alloc] initWithRootViewController:compose];
    //        [self presentViewController:nav animated:YES completion:nil];
}
@end
